41_Reading Encoders

Each hall-effect sensor on the encoder is supposed to create twelve pulses per revolution of the magnetic encoder disk.  The magnetic disk attached to the rear motor shaft will turn 298 times for every revolution of the output motor shaft.  If the motor is running at about 1 rev/s, then the pulses from the encoder output will be at a frequency of (298x12) 3.58 kHz.  Since the ELVIS Board oscilloscope was not reading this signal very well, I used one of the MCU’s GPIO pin as a digital input and connected the encoder signal to it. 

In the MCU I had the main loop to constantly read this input and to turn on an LED on another output pin whenever the signal was HIGH and turn it off when it was LOW so that I could see the encoder signal.  After downloading the program to the MCU, rotating the magnetic disk by hand caused the LED to blink.  The faster the disk was spun, the faster it would blink.  When the motor was driven by the motor-driver circuit, the LED would appear to stay on, changing brightness as the motor speed changed.

With the encoder apparently working, I had the program to count the number of times that the encoder signal turned to a HIGH.  Once the signal reached several thousand, the program would then reduce the motor’s duty cycle to 0%.  Running the program caused the motor to operate for several turns then turn off.  However, after several seconds, the program seemed to restart (or the MCU was resetting) causing the motor to run again for several turns then shut back off.